const path = require("path");
const process = require("process")
const cp = require("child_process")
const tmp = require("tmp");
let lib = require("../lib");
const fs = require("fs-extra");
const toolbox = require("../lib/toolbox");

toolbox.safeListDir("V:\\TO-UP-190621-xxxx-jlwtcd\\Below1GB\\directUp").then(async aps => {
  // debugger
  for (let ap of aps) {
    let list = await toolbox.safeListDir(ap.full_path);
    let rarPath = list.filter(e => e.relative_path.endsWith("1.rar"))
    cp.exec(`7z l -ba -p -slt -sccUTF-8 "${rarPath[0].full_path}"`, {
      env: ap.full_path
    }, (err, stdout, stderr) => {
      fs.writeFile(path.join(ap.full_path, "PackedFileList.fl"), stdout);
    })
    // debugger
  }
})

// lib.uploadablify_kd_dir(path.join(__dirname,"../tmp/TMP_发帖用"));

// tmp.file((err,name,fd,cb)=>{
//     debugger
//     fs.write(fd,`\uFEFF 我是谁 我在哪`,(err,written,str)=>{
//         debugger
//         fs.readFile(name,(err,data)=>{
//             debugger
//             console.log(data.toString());
//             cb();
//         })
//     })
// })

// let p= lib.rarPack([
//   "F:\\patricia\\GAL1905\\qbdown\\[190531] [TRYSET Break] ハメ堕ち課外授業 デラックス版\\NemuAndHaruka.png",
//   "G:\\BaiduyunBakcup\\53726-32\\Deployment\\en_AE_Deployment.xml",
//   "F:\\patricia\\CODE_Project\\lib-owhat\\bin",
//   // "G:\\BaiduyunBakcup\\Java语言程序设计 基础篇 原书第10版 ,梁勇著 .pdf"
// ], path.join(__dirname, "../tmp/233.rar"), 1.03);
// p.then(o=>{
//   debugger
// })

// lib.unrar(path.join(__dirname, "../tmp/我操.part1.rar"),
//   path.join(__dirname, "../tmp/P1/p2")
// ).then(o => {
//   debugger
// })

// lib.unpackWith7z(path.join(__dirname, "../tmp/我操.part2.rar"),
//   path.join(__dirname, "../tmp/P1/p2")
// ).then(o => {
//   debugger
// })

// lib.uploadablify(path.join(__dirname,"../tmp/"),165);
// lib.rarTest(path.join(__dirname,"../tmp/OOO.part1.rar")).then(o=>{
//   debugger
// })

// let rarFile = path.join(__dirname,
//   "../tmp/-tmp.rar")
// lib.listWith7z(rarFile).then(async o => {
//   let o_extrac = await lib.extractOneFileWith7z(rarFile, o.data.list[0].Path, 
//     path.join(__dirname, "../tmp/___k"));
//   debugger
// })

